CameraDevice Class

This type is an EasyAR Sense API in C#: CameraDevice . Some descriptions may not apply to Unity environment on this page.

This type is partially wrapped into Unity components: CameraDeviceFrameSource EditorCameraDeviceFrameSource . Members and instances of this type are not required to be used directly in most situations. Use this type by CameraDeviceFrameSource.Device EditorCameraDeviceFrameSource.Device instead of creating new instances when a few unwrapped API is desired for use.

Description

CameraDevice implements a camera device, which outputs InputFrame (including image, camera paramters, and timestamp). It is available on Windows, Mac, Android and iOS.

After open, start/stop can be invoked to start or stop data collection. start/stop will not change previous set camera parameters.

When the component is not needed anymore, call close function to close it. It shall not be used after calling close.

CameraDevice outputs InputFrame from inputFrameSource. inputFrameSource shall be connected to InputFrameSink for use. Refer to Overview .

bufferCapacity is the capacity of InputFrame buffer. If the count of InputFrame which has been output from the device and have not been released is more than this number, the device will not output new InputFrame , until previous InputFrame have been released. This may cause screen stuck. Refer to Overview .

On Android, it is required to add android.permission.CAMERA to AndroidManifest.xml for use.

On iOS, it is required to add NSCameraUsageDescription to Info.plist for use.


Methods

isAvailable

C#

public static bool isAvailable()

Checks if the component is available. It returns true only on Windows, Mac, Android or iOS.

androidCameraApiType

C#

public virtual AndroidCameraApiType androidCameraApiType()

Gets current camera API (camera1 or camera2) on Android. camera1 is better for compatibility, but lacks some necessary information such as timestamp. camera2 has compatibility issues on some devices.

setAndroidCameraApiType

C#

public virtual void setAndroidCameraApiType( AndroidCameraApiType type)

Sets current camera API (camera1 or camera2) on Android. It must be called before calling openWithIndex, openWithSpecificType or openWithPreferredType, or it will not take effect.

It is recommended to use CameraDeviceSelector to create camera with camera API set to recommended based on primary algorithm to run.

bufferCapacity

C#

public virtual int bufferCapacity()

InputFrame buffer capacity. The default is 8.

setBufferCapacity

C#

public virtual void setBufferCapacity(int capacity)

Sets InputFrame buffer capacity.

inputFrameSource

C#

public virtual InputFrameSource inputFrameSource()

InputFrame output port.

setStateChangedCallback

C#

public virtual void setStateChangedCallback( CallbackScheduler callbackScheduler, Optional<Action< CameraState >> stateChangedCallback)

Sets callback on state change to notify state of camera disconnection or preemption. It is only available on Windows.

requestPermissions

C#

public static void requestPermissions( CallbackScheduler callbackScheduler, Optional<Action< PermissionStatus , string>> permissionCallback)

Requests camera permission from operating system. You can call this function or request permission directly from operating system. It is only available on Android and iOS. On other platforms, it will call the callback directly with status being granted. This function need to be called from the UI thread.

cameraCount

C#

public static int cameraCount()

Gets count of cameras recognized by the operating system.

openWithIndex

C#

public virtual bool openWithIndex(int cameraIndex)

Opens a camera by index.

openWithSpecificType

C#

public virtual bool openWithSpecificType( CameraDeviceType type)

Opens a camera by specific camera device type. If no camera is matched, false will be returned. On Mac, camera device types can not be distinguished.

openWithPreferredType

C#

public virtual bool openWithPreferredType( CameraDeviceType type)

Opens a camera by camera device type. If no camera is matched, the first camera will be used.

start

C#

public virtual bool start()

Starts video stream capture.

stop

C#

public virtual void stop()

Stops video stream capture. It will only stop capture and will not change previous set camera parameters and connection.

close

C#

public virtual void close()

Close. The component shall not be used after calling close.

index

C#

public virtual int index()

Camera index.

type

C#

public virtual CameraDeviceType type()

Camera type.

cameraParameters

C#

public virtual CameraParameters cameraParameters()

Camera parameters, including image size, focal length, principal point, camera type and camera rotation against natural orientation. Call after a successful open.

setCameraParameters

C#

public virtual void setCameraParameters( CameraParameters cameraParameters)

Sets camera parameters. Call after a successful open.

size

C#

public virtual Vec2I size()

Gets the current preview size. Call after a successful open.

supportedSizeCount

C#

public virtual int supportedSizeCount()

Gets the number of supported preview sizes. Call after a successful open.

supportedSize

C#

public virtual Vec2I supportedSize(int index)

Gets the index-th supported preview size. It returns {0, 0} if index is out of range. Call after a successful open.

setSize

C#

public virtual bool setSize( Vec2I size)

Sets the preview size. The available nearest value will be selected. Call size to get the actual size. Call after a successful open. frameRateRange may change after calling setSize.

supportedFrameRateRangeCount

C#

public virtual int supportedFrameRateRangeCount()

Gets the number of supported frame rate ranges. Call after a successful open.

supportedFrameRateRangeLower

C#

public virtual float supportedFrameRateRangeLower(int index)

Gets range lower bound of the index-th supported frame rate range. Call after a successful open.

supportedFrameRateRangeUpper

C#

public virtual float supportedFrameRateRangeUpper(int index)

Gets range upper bound of the index-th supported frame rate range. Call after a successful open.

frameRateRange

C#

public virtual int frameRateRange()

Gets current index of frame rate range. Call after a successful open.

setFrameRateRange

C#

public virtual bool setFrameRateRange(int index)

Sets current index of frame rate range. Call after a successful open.

setFlashTorchMode

C#

public virtual bool setFlashTorchMode(bool on)

Sets flash torch mode to on. Call after a successful open.

setFocusMode

C#

public virtual bool setFocusMode( CameraDeviceFocusMode focusMode)

Sets focus mode to focusMode. Call after a successful open.

autoFocus

C#

public virtual bool autoFocus()

Does auto focus once. Call after start. It is only available when FocusMode is Normal or Macro.